package com.sjb.singleequipment;

import static com.sjb.singleequipment.RedisKeyConstant.SESSION_KEY_POSTFIX;
import static com.sjb.singleequipment.RedisKeyConstant.USER_EXTRA_INFO;
import static org.springframework.session.data.redis.RedisIndexedSessionRepository.DEFAULT_NAMESPACE;

/**
 * @Author:sjb
 * @CreateTime:2024-08-18
 * @Description: 快捷生成RedisKey
 * @Version：1.0
 */
public class RedisKeyUtil {

    /**
     * 获取已经登录用户的 IP 和sessionId 对应的key
     * @param userId
     * @return
     */
    public static String getUserExtraInfoKey(Long userId){
        return USER_EXTRA_INFO + String.valueOf(userId);
    }

    /**
     * 获取sesion信息对应的key
     * @param sessionId
     * @return
     */
    public static String getSessionKey(String sessionId){
        return DEFAULT_NAMESPACE + ":" + SESSION_KEY_POSTFIX + ":" + sessionId;
    }

    /**
     * 获取session中某一属性的key
     * @param attrName
     * @return
     */
    public static String getSessionAttrKey(String attrName){
        return SESSION_KEY_POSTFIX + ":" + attrName;
    }
}
